Recursively setting Inherited module/object attributes

I'm trying to put together a little dxl script to help me flatten out access rights in some old/unmaintained projects.

I used layout DXL to set each object in a module to inherited access rights, but the sheer number of modules makes this a pain to do. I've tried to put together a script to allow me to select a folder, and let it recursively set inherited access to sub-folders, modules and objects inside. However, the script appears to only run on the first folder and first module, and then quit out. I've been running it on a test project with 3 sub-folders and 1 to 2 formal modules in each folder.

Any help?
 

// Set Access Inherited (Recursive)
 
 
void setModuleInherited(Module cur_mod)
// Set the current module and all objects inside to inherited access
{
  Object cur_obj
 
  inherited(cur_mod)
 
  for cur_obj in cur_mod do
  {
    inherited(cur_obj)
  }
}
 
void setFolderInherited(Folder cur_fold)
{
  Module found_mod
  Folder sub_fold
  string NameItem
  Item cur_itm
  string iType = ""
 
  print name(cur_fold) "\n"
 
  // Set the current folder object to Inherited Access
  inherited(cur_fold)
 
  for cur_itm in cur_fold do
  // Check each item in the current folder for Sub-Folders
  {
 
    iType = type(cur_itm)
    NameItem = fullName(cur_itm)
 
    print NameItem ", " iType "\n"
 
    if (iType == "Formal")
    // If the item is a Module, set Access rights for it
    {
      found_mod = edit(NameItem,false)
    if (found_mod != null)
      {
        setModuleInherited(found_mod)
          save(found_mod)
          close(found_mod,false)
      }
    }
 
    if (iType == "Folder")
    // If the item is a Folder, get its name and create a
    // Folder object to recurse on
    {
 
      // If the folder is for the Change Proposal System,
      // leave it alone.  Otherwise, recurse
 
      if (NameItem != "Change Proposal System")
      {
        sub_fold = folder(cur_itm)
        if (sub_fold != null)
        {
          setFolderInherited(sub_fold)
        }
      }
    }
  }
}
 
Folder current_fold = current Folder
setFolderInherited(current_fold)

 


I've noticed that the script sometimes gets an unassigned item inside the

 

for cur_item in cur_fold do

loop, and I'm not sure how that happens.


dbinkis - Fri Dec 04 10:25:42 EST 2009

Re: Recursively setting Inherited module/object attributes
doors36677 - Fri Dec 04 11:11:10 EST 2009

Move your comment so they don't interfere with you loops.

Re: Recursively setting Inherited module/object attributes
dbinkis - Fri Dec 04 13:54:58 EST 2009

doors36677 - Fri Dec 04 11:11:10 EST 2009
Move your comment so they don't interfere with you loops.

Wow. Did that and it worked. Thanks!

I'm astonished that comments can affect DXL code. I don't know that I've ever encountered that before with other languages.

Re: Recursively setting Inherited module/object attributes
Peter_Albert - Mon Dec 07 03:13:54 EST 2009

dbinkis - Fri Dec 04 13:54:58 EST 2009
Wow. Did that and it worked. Thanks!

I'm astonished that comments can affect DXL code. I don't know that I've ever encountered that before with other languages.

A comment is anything which begins with '//'. A line which begins with empty spaces, followed by '//' is a (somewhat useless, but formally correct) statement, followed by a comment. This, plus the fact that if clauses do not require brackets around the following code blocks, explain your case.

if (false)
   // foo
{print "foo"}
print "bar"

produces "foobar" in the output pane, as the if clause only affects the following code block, which is

// foo

However,

if (false)
// foo
{print "foo"}
print "bar"

only produces "bar", as the complete line is a comment, and is as such ignored. If you want to indent comments, I suggest the following style:

if (false)
{ // foo
  print "foo"
} // foo
print "bar"

Repeating the code at the closing brackets becomes extremely handy when you end up with many nested if blocks.

Regards,

Peter

Re: Recursively setting Inherited module/object attributes
llandale - Mon Dec 07 17:34:23 EST 2009

Yeah, comments can be code. Your curr-item loop loops through the comment, and then one time executes the rest of the code. If the first item is a module it does that module, if its a folder it does nothing.

Your object loop should be "for cur_obj in entire cur_mod do". DOORS v9.2.0.1 has a bug and you might run into trouble settign inherited a deleted object.

You might want to set "Link" and "Descriptive" modules inherited as well. You might want to set sub "Project"s inherited as well.

Its good practice if you code your function better. In this case check for null folder and check for CPS folder at the top of the function. For debugging, print the error if so, and if not print the name of the folder.

  • Louie